import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)
export default new Vuex.Store({
    state: {
        name: 'tom',
        age: 0,
        stu: {
            ename: ''
        }
    },
    getters: {
        getName(state) {
            return state.name
        }
    },
    mutations: {
        setName(state, obj) {
            state.name = obj
            
        }
    },
    actions: {
        asyncSetName(context, obj) {
            // 调用了 mutations中的setName
            context.commit("setName", obj)
        }
    }
})